package com.aaa.tmr.controller;

import com.aaa.tmr.entity.Attendance;
import com.aaa.tmr.entity.ReturnBean;
import com.aaa.tmr.service.AttendanceService;
import com.aaa.tmr.util.Result;
import com.aaa.tmr.util.ReturnStatus;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * (Attendance)表控制层
 *
 * @author makejava
 * @since 2021-04-09 13:32:49
 */
@Controller
@RequestMapping("attendance")
public class AttendanceController {
    /**
     * 服务对象
     */
    @Resource
    private AttendanceService attendanceService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ResponseBody
    @RequestMapping("selectOne")
    public Result selectOne(Integer id) {
        return new Result(ReturnStatus.SUCCESS.getCode(),
                ReturnStatus.SUCCESS.getMessage(), 0,
                this.attendanceService.queryById(id));
    }

    /**
     * 跳转部门分页列表页面
     *
     * @return
     */
    @RequestMapping("toAttendance")
    public String toPage() {
        return "back/attendance-page";
    }

    /**
     * 跳转部门分页列表页面
     *
     * @return
     */
    @RequestMapping("toAttendanceEcharts")
    public String toEcharts() {
        return "back/attendanceEcharts";
    }
    /**
     * 通过实体作为筛选条件查询
     *
     * @return 对象列表
     */
    @ResponseBody
    @RequestMapping("queryAll")
    public Result queryAll(Integer page, Integer limit, Attendance attendance) {
        PageInfo pageInfo = attendanceService.queryAll(page, limit, attendance);
        return new Result(ReturnStatus.SUCCESS.getCode(),
                ReturnStatus.SUCCESS.getMessage(),
                pageInfo.getTotal(), pageInfo.getList());
    }

    /**
     * 新增数据
     *
     * @param attendance 实例对象
     * @return 实例对象
     */
    @ResponseBody
    @RequestMapping("insert")
    public Result insert(Attendance attendance) {

        return new Result(ReturnStatus.SUCCESS.getCode(),
                ReturnStatus.SUCCESS.getMessage(), 0,
                this.attendanceService.insert(attendance));
    }

    /**
     * 修改数据
     *
     * @param attendance 实例对象
     * @return 实例对象
     */
    @ResponseBody
    @RequestMapping("update")
    public Result update(Attendance attendance) {
        return new Result(ReturnStatus.SUCCESS.getCode(),
                ReturnStatus.SUCCESS.getMessage(), 0,
                this.attendanceService.update(attendance));
    }

    /**
     * 通过主键删除数据
     *
     * @param attendanceId 主键
     * @return 是否成功
     */
    @ResponseBody
    @RequestMapping("deleteById")
    public Result deleteById(Integer attendanceId) {
        return new Result(ReturnStatus.SUCCESS.getCode(),
                ReturnStatus.SUCCESS.getMessage(), 0,
                this.attendanceService.deleteById(attendanceId));
    }

    /**
     * @return
     * @create by: ydq
     * @description: 方法作用：出勤分析按代理人
     * @create time: 2020/12/30 20:03
     * @param:
     */
    @RequestMapping("showAgentChart")
    @ResponseBody
    public Result showAgentChart(String startTime, String endTime) {
        return new Result(ReturnStatus.SUCCESS.getCode(),
                ReturnStatus.SUCCESS.getMessage(), 0,
                this.attendanceService.showAgentChart(startTime,endTime));
    }
}
